﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sinacor.OMM.HealthMonitor.Entity.Common;

namespace Sinacor.OMM.HealthMonitor.Entity.OrderExecutor
{
    [Serializable()]
    public class Executor : IHealthDataReset
    {

        HealthEntityBase _healthEntityBase;

        public Executor()
        {
            _healthEntityBase = new HealthEntityBase();
            ErrorData = new ErrorData();
        }

        public Executor(HealthEntityBase healthEntityBase)
        {
            _healthEntityBase = healthEntityBase;
        }

        private long _numberOfExceptionsDataBase;

        public long NumberOfExceptionsDataBase
        {
            get { return _numberOfExceptionsDataBase; }
            set
            {
                _numberOfExceptionsDataBase = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        private TimeSpan _nextScheduleProcedure;

        public String NextScheduleProcedure
        {
            get { return _nextScheduleProcedure.ToString(); }
            set
            {
                _nextScheduleProcedure = TimeSpan.Parse(value);
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        private long _procedureExecutionTime;

        public long ProcedureExecutionTime
        {
            get { return _procedureExecutionTime; }
            set
            {
                _procedureExecutionTime = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        private long _limitProcedureExecutionTime;

        public long LimitProcedureExecutionTime
        {
            get { return _limitProcedureExecutionTime; }
            set
            {
                _limitProcedureExecutionTime = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        private ErrorData _errorData;

        public ErrorData ErrorData
        {
            get { return _errorData; }
            set
            {
                _errorData = value;
                _healthEntityBase.LastUpdate = DateTime.Now;
            }
        }

        public void Reset()
        {
            this._nextScheduleProcedure = TimeSpan.MinValue;
            this._numberOfExceptionsDataBase = 0;
            this._procedureExecutionTime = 0;
        }
    }
}
